package com.byt.common.util;

import android.app.Activity;

import com.byt.common.bean.VersionInfo;
import com.byt.common.view.dialog.UpdateDialog;


/**
 * Created by admin on 2018/4/11.
 */

public class UpdateVersionUtil {

    public static void showUpdateDialog(Activity mContext, VersionInfo versionInfo, String apkName) {
        int currentCode = APKVersionCodeUtils.getVersionCode(mContext);
        int code;
        try {
            code = Integer.parseInt(versionInfo.getVersion_code());
        } catch (Exception e) {
            code = 0;
        }
        if (currentCode < code) { // 需更新
            UpdateDialog alertDialog = new UpdateDialog(mContext, "发现新版本更新(V" + versionInfo.getVersion_name() + ")", versionInfo.getContent(),
                    versionInfo.getUpdate_flag() != 1, new UpdateDialog.OnDialogButtonClickListener() {

                @Override
                public void onDialogButtonClick(boolean isPositive) {
                    if (isPositive) {
                        new VersionManager(mContext, versionInfo, apkName);
                    } else {
                        if (versionInfo.getUpdate_flag() == 1) {
                            mContext.finish();
                        }
                    }
                }
            });
            alertDialog.show();

        }
    }
}
